home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11621 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.0 KB  |  77 lines

  1. Path: telepost.no!usenet
  2. From: Carsten Arnholm <ca@sesam.dnv.no>
  3. Newsgroups: comp.lang.c++
  4. Subject: For Experts: How to load a DLL dynamically ?
  5. Date: 15 Mar 1996 13:23:22 GMT
  6. Organization: DNV
  7. Message-ID: <4ibr0a$8f9@nms.telepost.no>
  8. NNTP-Posting-Host: hugin.sesam.dnv.no
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=us-ascii
  11. Content-Transfer-Encoding: 7bit
  12. X-Mailer: Mozilla 1.1 (Windows; I; 32bit)
  13.  
  14. Hi everyone,
  15.  
  16. I have a problem which I'm sure some of you experts can solve (???):
  17. I'm using MSVC++ 4.0 under Windows NT 3.51.
  18.  
  19. I am unable to load a DLL exporting classes. If the DLL only exports
  20. simple API functions, I can do:
  21.  
  22.     // load the library
  23.     HINSTANCE        myDLL   = LoadLibrary("myDLL.dll");       
  24.     const FARPROC  myDLLfunc = GetProcAddress(myDLL ,"myDLLfunc");
  25.     
  26.     // call a function in the DLL that returns an int
  27.     int value = myDLLfunc();
  28.    
  29.     // DLL no longer needed
  30.     FreeLibrary(myDLL);
  31.  
  32. This is straightforward ...
  33.  
  34.  
  35. But what do I do if I have a DLL which export classes ? i.e.
  36.  
  37. #ifdef DLL_IMPLEMENTATION
  38.    #define IMPORT_EXPORT _declspec(dllexport)
  39. #else
  40.    #define IMPORT_EXPORT _declspec(dllimport)
  41. #endif
  42.  
  43. class IMPORT_EXPORT DLLfoo {   // class exported from dll
  44. public:
  45.    DLLfoo();                   // constructor
  46.    int bar();                  // some member function
  47. private:
  48.    int value;
  49. };
  50.  
  51. In an application using the DLL, I want to:
  52.  
  53.    DLLfoo foo;                 // create object from DLL class DLLfoo
  54.    int somevalue = foo.bar();  // call member function of that class
  55.  
  56. This is no problem if I link the application using the import library
  57. of my DLL, but that means that the DLL is "started" together with the 
  58. application, whether I need it or not.
  59.  
  60. If I don't link with the import library, there are lots of unresolved
  61. symbols (of course), and I can't figure out how to do something
  62. similar to  LoadLibrary/GetProcAddress for my classes and their members.
  63.  
  64. Any good Ideas ????
  65.  
  66. Would appreciate if you copied your reply to 
  67. my e-mail address: ca@sesam.dnv.no
  68.  
  69.  
  70. Thanks,
  71. Carsten Arnholm
  72.  
  73.  
  74.  
  75.  
  76.  
  77.